using System;
using System.Linq.Expressions;
using System.Reflection;
using esquireclockscreensaver.Properties;

namespace esquireclockscreensaver.Utils
{
    internal static class ReflectionUtils
    {
        public static string GetPropertyName<T>(Expression<Func<T>> propertyGetter)
        {
            var name = (propertyGetter.Body as MemberExpression).With(x => x.Member as PropertyInfo).With(x => x.Name);
            if(string.IsNullOrEmpty(name))
            {
                throw new ArgumentException(Resources.ReflectionUtils_GetPropertyName_is_not_a_property, "propertyGetter");
            }
            return name;
        }
    }
}